<template>
  <span class="mes_cell">
    <template v-if="matchComp('turnoverProcessStatus')">
      <turnover-progress-status :data="row"></turnover-progress-status>
    </template>
    <template v-else-if="matchComp('boolType')">
      <bool-type :data="{label: row[column.boolTypeLabel], value: row[column.boolTypeValue]}"></bool-type>
    </template>
    <template v-else-if="matchComp('deviceStatus')">
      <device-status :data="row"></device-status>
    </template>
    <template v-else-if="matchComp('feedMaterialState')">
      <feed-material-state :data="row"></feed-material-state>
    </template>
    <template v-else-if="matchComp('inspectionType')">
      <inspection-type :data="row"></inspection-type>
    </template>
    <template v-else-if="matchComp('materialState')">
      <material-state :data="row"></material-state>
    </template>
    <template v-else-if="matchComp('priority')">
      <priority :data="row"></priority>
    </template>
    <template v-else-if="matchComp('processState')">
      <process-state :data="row"></process-state>
    </template>
    <template v-else-if="matchComp('taskType')">
      <task-type :data="row"></task-type>
    </template>
    <template v-else-if="matchComp('turnoverProgressStatus')">
      <turnover-progress-status :data="row"></turnover-progress-status>
    </template>
    <template v-else-if="matchComp('turnoverStatus')">
      <turnover-status :data="row"></turnover-status>
    </template>
    <template v-else-if="matchComp('weekPlanStatus')">
      <week-plan-status :data="row"></week-plan-status>
    </template>
    <template v-else-if="matchComp('workSchedule')">
      <work-schedule :data="row"></work-schedule>
    </template>
    <template v-else-if="matchComp('workStageProcessStatus')">
      <work-stage-process-status :data="row"></work-stage-process-status>
    </template>
    <template v-else-if="matchComp('workStageStatus')">
      <work-stage-status :data="row"></work-stage-status>
    </template>
    <template v-else-if="matchComp('workState')">
      <work-state :data="row"></work-state>
    </template>
    <template v-else-if="matchComp('materialStorageStatus')">
      <material-storage-status :data="row"></material-storage-status>
    </template>
    <template v-else-if="matchComp('storageType')">
      <storage-type :data="row"></storage-type>
    </template>
    <template v-else-if="matchComp('returnStatus')">
      <material-return-status :data="row"></material-return-status>
    </template>
    <template v-else-if="matchComp('deviceUploadStatus')">
      <device-upload-status :data="row"></device-upload-status>
    </template>
    <template v-else-if="matchComp('fixtureStatus')">
      <fixture-status :data="row"></fixture-status>
    </template>
    <template v-else-if="matchComp('instrumentStatus')">
      <instrument-status :data="row"></instrument-status>
    </template>
    <template v-else-if="matchComp('maintainStatus')">
      <maintain-status :data="row"></maintain-status>
    </template>
    <template v-else-if="matchComp('materialReturnStatus')">
      <material-return-status :data="row"></material-return-status>
    </template>
    <template v-else-if="matchComp('repairStatus')">
      <repair-status :data="row"></repair-status>
    </template>
    <template v-else-if="column.formatToDay">{{row[column.prop] | timeFormat}}</template>
    <template v-else-if="column.formatToNumber">{{row[column.prop] || 0}}</template>
    <template v-else>{{row[column.prop]}}</template>
  </span>
</template>

<script>
import {
  // 布尔类型
  BoolType,
  // 设备状态
  DeviceStatus,
  // 设备数据上传状态
  DeviceUploadStatus,
  // 上料状态
  FeedMaterialState,
  // 工装夹具状态
  FixtureStatus,
  // 检验类型
  InspectionType,
  // 仪器状态
  InstrumentStatus,
  // 保养状态
  MaintainStatus,
  // 退库状态
  MaterialReturnStatus,
  // 要料状态
  MaterialState,
  // 入库状态
  MaterialStorageStatus,
  // 优先级
  Priority,
  // 处理状态类型
  ProcessState,
  // 维修状态
  RepairStatus,
  // 入库类型
  StorageType,
  // 周转批次任务类型
  TaskType,
  // 周转进度状态
  TurnoverProgressStatus,
  // 周转状态
  TurnoverStatus,
  // 周计划状态
  WeekPlanStatus,
  // 工单进度状态
  WorkSchedule,
  // 工序进度状态
  WorkStageProcessStatus,
  // 工序状态
  WorkStageStatus,
  // 工单状态
  WorkState,
} from '../mesDict'

export default {
  name: 'MesCell',
  components: {
    BoolType,
    DeviceStatus,
    DeviceUploadStatus,
    FeedMaterialState,
    FixtureStatus,
    InspectionType,
    InstrumentStatus,
    MaintainStatus,
    MaterialReturnStatus,
    MaterialState,
    MaterialStorageStatus,
    Priority,
    ProcessState,
    RepairStatus,
    StorageType,
    TaskType,
    TurnoverProgressStatus,
    TurnoverStatus,
    WeekPlanStatus,
    WorkSchedule,
    WorkStageProcessStatus,
    WorkStageStatus,
    WorkState,
  },
  props: {
    column: {
      type: Object,
      default() {
        return {}
      }
    },
    row: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  methods: {
    // 组件名同时支持'comp','component'属性传入，组件名同时支持首字母大写和小写
    matchComp(name) {
      if (this.column.hasOwnProperty('comp')) {
        return this.column.comp === name || this.column.comp === name.charAt(0).toUpperCase() + name.slice(1)
      } else {
        return this.column.component === name || this.column.comp === name.charAt(0).toUpperCase() + name.slice(1)
      }
    }
  }
}
</script>
